package com.gokzzz.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gokzzz.dto.SysQuartzLogSearchQueryDTO;
import com.gokzzz.entity.SysQuartzLog;
import com.gokzzz.mapper.SysQuartzLogMapper;
import com.gokzzz.response.PageData;
import com.gokzzz.service.ISysQuartzLogService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @author gokzzz
 * @date 2022-04-24 14:46
 */

@Service
@RequiredArgsConstructor
public class SysQuartzLogServiceImpl extends ServiceImpl<SysQuartzLogMapper, SysQuartzLog> implements ISysQuartzLogService {

    private final SysQuartzLogMapper sysQuartzLogMapper;

    @Override
    public PageData<SysQuartzLog> listLogByPage(SysQuartzLogSearchQueryDTO sysQuartzLogSearchQueryDTO, Long page, Long size) {
        LambdaQueryWrapper<SysQuartzLog> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(CharSequenceUtil.isNotBlank(sysQuartzLogSearchQueryDTO.getJobName()), SysQuartzLog::getJobName, sysQuartzLogSearchQueryDTO.getJobName());
        wrapper.eq(ObjectUtil.isNotNull(sysQuartzLogSearchQueryDTO.getSuccess()), SysQuartzLog::getSuccess, sysQuartzLogSearchQueryDTO.getSuccess());
        if (CollUtil.isNotEmpty(sysQuartzLogSearchQueryDTO.getCreateTime()) && ObjectUtil.isNotNull(sysQuartzLogSearchQueryDTO.getCreateTime())) {
            wrapper.between(SysQuartzLog::getCreateTime, sysQuartzLogSearchQueryDTO.getCreateTime().get(0), sysQuartzLogSearchQueryDTO.getCreateTime().get(1));
        }
        Page<SysQuartzLog> sysQuartzLogPage = sysQuartzLogMapper.selectPage(new Page<>(page, size), wrapper);
        return new PageData<>(sysQuartzLogPage.getCurrent(), sysQuartzLogPage.getSize(), sysQuartzLogPage.getTotal(), sysQuartzLogPage.getRecords());
    }
}
